﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InHD.model;
using InHD.commands;
using System.Windows.Input;

namespace InHD.viewmodels
{
    class SuppliersListViewModel:WorkspaceViewModel
    {

        #region Value Property
        private List<Supplier> _supplierRowCollection;
        private int _rowIndex = -1;
        public string commandExcute = string.Empty;
        private Supplier _supplier;
        #endregion

        #region Constructor
        public SuppliersListViewModel( List<Supplier> listSupplier)
        {
            _supplierRowCollection = listSupplier;
        }
        #endregion

        #region Presentation Property
        public List<Supplier> SupplierRowCollection
        {
            get
            {
                return _supplierRowCollection;
            }
            set
            {
                if (_supplierRowCollection != value)
                {
                    _supplierRowCollection = value;
                    OnPropertyChanged("SupplierRowCollection");
                }
            }
        }

        public int RowIndex
        {
            get
            {
                return this._rowIndex;
            }
            set
            {
                this._rowIndex = value;
                OnPropertyChanged("RowIndex");
            }
        }

        public Supplier SelectedSupplier
        {
            get
            {
                return this._supplier;
            }
            set
            {
                if (value != null)
                {
                    this._supplier = value;
                }
            }
        }
        #endregion

        #region Command 
        private RelayCommand _viewSupplierCommand;
        public ICommand ViewSupplierCommand
        {
            get
            {
                if (_viewSupplierCommand == null)
                {
                    _viewSupplierCommand = new RelayCommand(
                        (param) => this.ViewSupplier(), (param)=>this.CanView);
                }
                return _viewSupplierCommand;
            }
        }

        private RelayCommand _addNewSupplierCommand;
        public ICommand AddNewSupplierCommand
        {
            get
            {
                if (_addNewSupplierCommand == null)
                {
                    _addNewSupplierCommand = new RelayCommand(
                        (param) => this.AddNewSupplier());
                }
                return _addNewSupplierCommand;
            }
        }
        #endregion

        #region Command Method
        void ViewSupplier()
        {
            commandExcute = "View";
            OnRequestClose();
        }

        void AddNewSupplier()
        {
            commandExcute = "Add";
            OnRequestClose();
        }
        #endregion

        public bool CanView { get { if (this.SelectedSupplier == null) return false; else return true; } }
    }
}
